/*===========================================================================================================================
	Wolf Prop Protection
		By Goluch
			DO NOT UPLOAD TO GARRYSMOD.ORG
			
			
	Name: WPP.ShareMenu
	Purpose: Creates the Share Menu.
	Author: Goluch
===========================================================================================================================*/
function WPP.ShareMenu()
	if ( WPP._Menu ) then
		WPP._Menu:Remove();
		return;
	end
	
	local Wide = 200
	local Tall = 30 + (#WPP.Actions * 25);
	local Gradient = surface.GetTextureID( "vgui/gradient_down" );
	
	local Entity = LocalPlayer():GetEyeTraceNoCursor( ).Entity;
	if ( !Entity ) or ( !WPP:IsValid(Entity) ) then
		WPP.Hint = "Look at somthing!";
		WPP.Hint_Color = Color(255,0,0);
		WPP.Hint_Time = CurTime() + 5;
		return;
	end
	
	if ( !WPP:IsOwner(Entity,LocalPlayer()) ) then
		WPP.Hint = "You do not own that!";
		WPP.Hint_Color = Color(255,0,0);
		WPP.Hint_Time = CurTime() + 5;
		return;
	end
	
	local Frame = vgui.Create("DFrame");
	Frame:SetTitle("Wolf Prop Share!");
	Frame:SetDraggable(true);
	Frame:SetSizable(false);
	Frame:SetDeleteOnClose(true);
	Frame:SetMouseInputEnabled( true );
	Frame:SetSize(Wide,Tall);
	
	for Index,Action in ipairs(WPP.Actions) do
		local Tick = vgui.Create("DCheckBoxLabel",Frame);
		Tick:SetPos(5,Index * 25);
		Tick:SetText( Action );
		Tick:SizeToContents();
		Tick:SetValue( WPP:GetShare(Entity,Index) );
		
		Tick.OnChange = function( Bool )
			local Value = 0;
			if ( Bool ) then
				Value = 1;
			end
			
			RunConsoleCommand("wpp","share",Entity:EntIndex(),Index,Value);
		end
		
	end
	
	function Frame:Close()
		WPP._Menu = nil
		self:Remove()
	end
	
	function Frame:Paint()
		surface.SetDrawColor( 0, 0, 0, 200 );
		surface.SetTexture( Gradient );
		surface.DrawTexturedRectRotated( self:GetWide()/2, 12, self:GetWide() , 22 , 180);
		
		surface.SetDrawColor( 0, 0, 0, 200 );
		surface.DrawRect( 0, 22, self:GetWide() , self:GetTall() - 22 );
		
		surface.SetDrawColor( 255,255,255,255 );
		surface.DrawOutlinedRect( 0, 0, self:GetWide() , self:GetTall() )
	end
	
	Frame:Center();
	Frame:MakePopup();
	
	WPP._Menu = Frame;
	
end

concommand.Add("wpp_share",WPP.ShareMenu);